<template>
  <div>
    <el-row>
      <el-col :span="24">
        <el-checkbox v-model="radio">继承</el-checkbox>
      </el-col>
    </el-row>
    <el-row v-if="!radio">
      <el-col :span="24">
        <el-select v-model="dataSource" placeholder="请选择" @change="change">
          <el-option
              v-for="item in dataSources"
              :key="item.uuid"
              :label="item.name"
              :value="item.uuid">
          </el-option>
        </el-select>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import api_collect from "@/api/api_collect";

export default {
  name: "DataSource",
  data() {
    return {
      dataSources: [],
      dataSource: "inherit"
    }
  },
  props:{
    value:{
      type:String,
      default:"inherit"
    }
  },
  computed:{
    radio: {
      get() {
        return this.dataSource==="inherit"
      },
      set(value){//回调函数：当属性值发生改变时回调，更新相关的属性数据
        if(value){
          this.dataSource="inherit"
        }else {
          this.dataSource=""
        }
      }
    },
  },
  mounted() {
    this.dataSource=this.value||"inherit"
    api_collect.getList().then(res => {
      if (res.code === 0) {
        this.dataSources = res.data;
      } else {
        this.$message.error(res.msg);
      }
    }).catch(err => {
      console.error(err)
      this.$message.error(err);
    })
  },

  watch:{
    value(){
      this.dataSource=this.value||"inherit"
    }
  },
  methods:{
    change(){
      this.$emit('input', this.dataSource)
    }
  }
}
</script>

<style scoped>

</style>
